package com.zimmur.app.mocolink.manage.web.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zimmur.app.mocolink.domain.model.BackgroundImage;
import com.zimmur.app.mocolink.manage.web.common.ReturnJsonEntity;
import com.zimmur.app.mocolink.manage.web.common.StatusCodeEnum;
import com.zimmur.app.mocolink.service.IBackgroundImageService;

@Controller
@RequestMapping("/backImage")
public class BackgroundController extends BaseController {

	@Autowired
	private IBackgroundImageService backgroundImageService;
	
	@RequestMapping("/index")
	public String index(ModelMap model){
		List<BackgroundImage> list =backgroundImageService.selectAll();
		model.addAttribute("list", list);
		return "/center/backImage/list";
	}
	@RequestMapping("/edit")
	public String edit(ModelMap model){
		Integer id = getParam("id", 0);
		BackgroundImage image = backgroundImageService.selectById(id);
		model.addAttribute("image", image);
		return "/center/backImage/edit";
	}
	
	@ResponseBody
	@RequestMapping("/save")
	public ReturnJsonEntity save(BackgroundImage image){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum codeEnum = StatusCodeEnum.CODE100000;
		int flag = backgroundImageService.update(image);
		if(flag>0){
			codeEnum = StatusCodeEnum.CODE000000;
		}
		entity.init(codeEnum);
		return entity;
	}
}
